package com.jiazhong.example.project.bookstore.front.listener;

import com.alibaba.fastjson.JSONArray;
import com.jiazhong.example.project.bookstore.commons.bean.RocketMQOrder;
import com.jiazhong.example.project.bookstore.commons.bean.Wuliu;
import com.jiazhong.example.project.bookstore.front.service.WuliuService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

// 物流消费者
@Slf4j
@Component
//@RocketMQMessageListener(consumerGroup = "order_success_3", topic = "Order", selectorExpression = "transaction", messageModel = MessageModel.BROADCASTING)
public class OrderSuccessLogisticsListener implements RocketMQListener<String> {
    @Resource
    private WuliuService wuliuService;

    @Override
    public void onMessage(String s) {
        log.info("开始执行物流添加操作");
        RocketMQOrder rocketMQOrder = JSONArray.parseObject(s, RocketMQOrder.class);
        log.info("物流，rocketMQOrder:{}", rocketMQOrder);
        Wuliu wuliu = new Wuliu();
        wuliu.setLogisticsId(rocketMQOrder.getLogisticsId());
        wuliu.setOrderId(rocketMQOrder.getOrderId());
        wuliuService.save(wuliu);
    }
}
